﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace IDE
{
    public class MenuOption
    {
        public enum MenuType
        {
            Auto,
            Custom,
        }
        public MenuType menuType;
        public string menuPath;
        //只能幸福二选一，如果是Auto模式，通过插件的OnMenuClick接口通知按下

        //如果是custom模式,则放置一个自定义MenuItem，事件也都不管
        public MenuItem customMenu;
    }
    public class FileTypeDesc
    {
        //public string type;//type 和 extname 定位重复
        public string extname;
        public string description;
        public ImageSource icon;
    }
    public class PanelInfo
    {
        public string type;
        public string title;
        public string description;
        public int defaultWidth;
        public int defaultHeight;
    }
    public interface IDocument
    {
        UIElement Editor
        {
            get;
        }
        string Filename
        {
            get;
        }
        bool Save();

        event Action Change;

    }
    //对插件做一些约定
    public interface IPlugin
    {
        string Name
        {
            get;
        }
        I_IDE IDE
        {
            get;
            set;
        }
        /// <summary>
        /// 面板扩展
        /// </summary>
        PanelInfo[] panels
        {
            get;
        }
        UIElement CreatePanelUI(string type);
        ///文件类型扩展
        FileTypeDesc[] filetypes
        {
            get;
        }
        IDocument OpenFile(string extname, string filename, bool writeable);
        void CreateEmptyFile(string extname, string filename);

        /// <summary>
        /// 插件扩展的工具栏
        /// </summary>
        ToolBar[] toolbars
        {
            get;
        }

        //IDE遍历MenuItem，自动建立，当Click时
        //呼叫OnMenuClick
        //CustomMenu 不会有Click事件，自行处理
        MenuOption[] MenuItem
        {
            get;
        }
        void OnMenuClick(string path);


    }

    public interface IPileLine
    {
        void Send(string tag, string arg);
        void SendBin(string tag, byte[] arg);

        void Care(Action<string, string> onRecv, Action<string, byte[]> onRecvBin);
    }
    public interface I_IDE
    {//对IDE做一些约定
        bool OpenFile(string fullfilename, bool writeable);
        bool ShowPanel(string plugin, string paneltype);

        string curFile
        {
            get;
        }
        void SaveCurFile();
        void SaveAllFile();

        /// <summary>
        /// 询问IDE 某个插件是否存在
        /// </summary>
        /// <param name="pluginname"></param>
        /// <returns></returns>
        bool HasPlugin(string pluginname);

        ///插件间互相通讯的方法，发出消息，谁关心谁拿走
        IPileLine GetPipeline(string name);


        //一组放共享数据的接口，插件间交换数据的手段 一
        void SetData_ByteArray(string key, byte[] data);
        byte[] GetData_ByteArray(string key);
        void SetData_String(string key, string data);
        string GetData_String(string key);

    }
}


